package com.liuyjy.controller;


import com.liuyjy.base.common.util.ObjConvertUtil;
import com.liuyjy.encryptDecrypt.Decrypt;
import com.liuyjy.entity.ComplexRequest;
import com.liuyjy.entity.UserReps;
import com.liuyjy.entity.UserReq;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/decrypt2")
public class NoTestController {

    @PostMapping("/v1")
    public UserReps decrypt(@RequestBody UserReq userReq) {
        log.info("解密前对象：{},id={}", userReq, userReq.getId());
        UserReps convert = ObjConvertUtil.convert(userReq, UserReps.class);
//        UserReps convert = new UserReps();
//        BeanUtils.copyProperties(userReq, convert);
        log.info("解密后对象：{},id={}", userReq, userReq.getId());
        return convert;
    }

    /**
     * 处理复杂数据结构示例
     *
     * @param request 自动解密嵌套对象和集合
     * @return 自动加密响应字段
     */
    @PostMapping("/process")
    public ComplexRequest process(@RequestBody @Decrypt ComplexRequest request) {
        log.info("解密前对象：{},id={}", request, request.getEncryptedField());
        //UserReps convert = ObjConvertUtil.convert(userReq, UserReps.class);
        log.info("解密后对象：{},id={}", request, request.getEncryptedField());
        return request;
    }

}
